package com.vegetable.modules.controller.test;

import com.vegetable.common.utils.MessageUtils;
import com.vegetable.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.web.bind.annotation.*;

/**
 * 消息测试控制器
 *
 * @author Qoder
 */
@RestController
@RequestMapping("/test")
@Api(value = "消息测试", tags = "消息测试")
public class MessageTestController {

    /**
     * 发送消息请求参数
     */
    @Data
    public static class SendMessageRequest {
        private Long receiverUserId;
        private String title;
        private String content;
        private Integer type = 1;
        private Integer important = 0;
        private String redirectUrl;
    }

    /**
     * 发送消息测试接口
     */
    @PostMapping("/sendMessage")
    @ApiOperation(value = "发送消息测试", notes = "发送带跳转链接的消息测试接口")
    public R<Boolean> sendMessage(@RequestBody SendMessageRequest request) {
        try {
            boolean result;
            if (request.getRedirectUrl() != null && !request.getRedirectUrl().isEmpty()) {
                // 发送带跳转链接的消息
                result = MessageUtils.sendMessage(
                    request.getReceiverUserId(),
                    request.getTitle(),
                    request.getContent(),
                    request.getRedirectUrl(),
                    request.getType(),
                    request.getImportant()
                );
            } else {
                // 发送普通消息
                result = MessageUtils.sendMessage(
                    request.getReceiverUserId(),
                    request.getTitle(),
                    request.getContent(),
                    request.getType(),
                    request.getImportant()
                );
            }
            return R.data(result);
        } catch (Exception e) {
            return R.fail("发送消息失败: " + e.getMessage());
        }
    }
}